<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>大事件-后台登录页</title>
  <link rel="stylesheet" type="text/css" href="css/reset.css" />
  <link rel="stylesheet" type="text/css" href="css/iconfont.css" />
  <link rel="stylesheet" type="text/css" href="css/main.css" />
  <!-- 引入bootstrap的css文件 -->
  <link rel="stylesheet" href="./libs/bootstrap/css/bootstrap.min.css" />
  
  <!-- 引入jq文件 -->
  <script src="./libs/jquery-1.12.4.min.js"></script>
  <!-- 引入bootstrap的js文件 -->
  <script src="./libs/bootstrap/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="./../../../../layui/css/layui.css">
  <script src="./../../../../layui/layui.js"></script>
</head>

<body>
  <div class="main_wrap">
    <div class="header">
      <a href="#" class="logo"><img src="images/logo.png" alt="" /></a>
      <div class="copyright">
        CopyRight © 2019 深圳百秀信息技术股份有限公司<br />All Rights Reserved
      </div>
    </div>

    <div class="login_form_con">
      <div class="login_title"></div>
      <form class="login_form">
        <i class="iconfont icon-user"></i>
        <i class="iconfont icon-key"></i>
        <input type="text" class="input_txt" placeholder="邮箱/手机号" />
        <input type="password" class="input_pass" placeholder="密码" />
        <input type="submit" class="input_sub" value="登 录" />
      </form>
    </div>
  </div>

  <script>
    $(function () {
      $('.input_sub').on('click', function (e) {
        e.preventDefault()
        const username = $('.input_txt').val().trim()
        const password = $('.input_pass').val().trim()
        let loadId = 0
        if (username == '' || password == '') {
          alert('用户名或密码不能为空')
          return
        }


        $.ajax({
          type: 'post',
          url: 'http://localhost:8080/api/v1/admin/user/login',
          data: {
            username,
            password
          },
          // 请求发送前
          beforeSend: function () {
            // layer.load()会返回一个ID值，关闭效果需要ID值
            loadId = layer.load()
            /* layer.alert('沙雕',{icon:1})
            layer.msg('大沙雕',{icon:5})
            layer.load(1) */
          },
          // 请求发送后
          complete:function(){
            // 关闭加载效果，括号里面是效果的ID
            layer.close(loadId)
          },
          success: function (backData) {
            // console.log(token);
            if(backData.token){
              localStorage.setItem('token',backData.token)
              window.location.href = './index.html'
            }else{
              layer.alert(backData.msg)
              // window.location.reload()
            }
          }
        })
      })
    })
  </script>
</body>

</html>